package com.xzz;

/**
 * @author 黄会准
 * @since 2020-11-18
 */

import com.sun.deploy.util.StringUtils;

import java.util.Arrays;

/**
 * 给定一个字符串，你需要反转字符串中每个单词的字符顺序，同时仍保留空格和单词的初始顺序。
 * <p>
 *  
 * <p>
 * 示例：
 * <p>
 * 输入："Let's take LeetCode contest"
 * 输出："s'teL ekat edoCteeL tsetnoc"
 */
public class ReverseWords {
    public static void main(String[] args) {
        System.out.println(reverseWords("Let's take LeetCode contest"));
        System.out.println(reverseWords("s'teL ekat edoCteeL tsetnoc"));
    }

    public static String reverseWords(String s) {
        String[] strings = s.split(" ");
        StringBuffer str = new StringBuffer();
        for (int i = 0; i < strings.length; i++) {
            str.append(new StringBuffer( strings[i] ).reverse().toString()).append(" ");
        }
        return str.toString().trim();
    }
}
